﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="insertClassData.aspx.cs" Inherits="Staff_insertClassData" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>新增開課資料</title>
    <style type="text/css">


        .style1
        {
            font-family: 微軟正黑體;
            font-size: xx-large;
            text-align: center;
        }
        .style2
        {
            text-align: right;
        }
        .style3
        {
            text-align: center;
        }
        .style4
        {
            width: 75%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="style2">
    
        <div class="style3">
    
        <span class="style1">新增開課資料</span><br />
            <asp:SqlDataSource ID="SqlDataSource4" runat="server" 
                ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
                SelectCommand="SELECT [TeacherName], [TeacherId] FROM [Teacher]">
            </asp:SqlDataSource>
            <asp:SqlDataSource ID="SqlDataSource5" runat="server" 
                ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
                DeleteCommand="DELETE FROM [Teaching] WHERE [serial] = @serial" 
                InsertCommand="INSERT INTO [Teaching] ([TeacherId], [CourseId]) VALUES (@TeacherId, @CourseId)" 
                SelectCommand="SELECT * FROM [Teaching]" 
                UpdateCommand="UPDATE [Teaching] SET [TeacherId] = @TeacherId, [CourseId] = @CourseId WHERE [serial] = @serial">
                <DeleteParameters>
                    <asp:Parameter Name="serial" Type="Int32" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:ControlParameter ControlID="DropDownList2" Name="TeacherId" 
                        PropertyName="SelectedValue" Type="Int32" />
                    <asp:SessionParameter Name="CourseId" SessionField="courseId" Type="Int32" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="TeacherId" Type="Int32" />
                    <asp:Parameter Name="CourseId" Type="Int32" />
                    <asp:Parameter Name="serial" Type="Int32" />
                </UpdateParameters>
            </asp:SqlDataSource>
        <br />
        </div>
        <div class="style3">
            <table align="center" class="style4">
                <tr>
                    <td colspan="2">
                        授課教師：<asp:DropDownList ID="DropDownList2" runat="server" 
                            DataSourceID="SqlDataSource4" DataTextField="TeacherName" 
                            DataValueField="TeacherId">
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
                            CellPadding="4" DataKeyNames="CourseId" DataSourceID="SqlDataSource1" 
                            DefaultMode="Insert" ForeColor="#333333" GridLines="None" Height="50px" 
                            style="text-align: center" Width="449px" 
                            oniteminserted="DetailsView1_ItemInserted">
                            <AlternatingRowStyle BackColor="White" />
                            <CommandRowStyle BackColor="#FFFFC0" Font-Bold="True" />
                            <FieldHeaderStyle BackColor="#FFFF99" Font-Bold="True" />
                            <Fields>
                                <asp:TemplateField HeaderText="當年課程編號" SortExpression="CourseId">
                                    <EditItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("CourseId") %>'></asp:Label>
                                    </EditItemTemplate>
                                    <InsertItemTemplate>
                                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("CourseId") %>'></asp:TextBox>
                                    </InsertItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("CourseId") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="CourseName" HeaderText="課程名稱" 
                                    SortExpression="CourseName" />
                                <asp:BoundField DataField="Year" HeaderText="開設年分" SortExpression="Year" />
                                <asp:BoundField DataField="Semester" HeaderText="上下學期" 
                                    SortExpression="Semester" />
                                <asp:TemplateField HeaderText="介紹" SortExpression="Intro">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Intro") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                    <InsertItemTemplate>
                                        <asp:TextBox ID="TextBox1" runat="server" Height="74px" 
                                            Text='<%# Bind("Intro") %>' TextMode="MultiLine" Width="240px"></asp:TextBox>
                                    </InsertItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Intro") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:CheckBoxField DataField="IsLimitNum" HeaderText="是否限制人數" 
                                    SortExpression="IsLimitNum" />
                                <asp:BoundField DataField="LimitNum" HeaderText="人數上限" 
                                    SortExpression="LimitNum" />
                                <asp:BoundField DataField="Point" HeaderText="學分" SortExpression="Point" />
                                <asp:BoundField DataField="Length" HeaderText="單周授課時數" 
                                    SortExpression="Length" />
                                <asp:CommandField ButtonType="Button" ShowInsertButton="True" />
                            </Fields>
                            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                        </asp:DetailsView>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                    <td>
                        &nbsp;</td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
                            DataSourceID="SqlDataSource2" DataTextField="Year" DataValueField="Year" 
                            onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        &nbsp;</td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                            BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" 
                            CellPadding="4" DataKeyNames="CourseId" DataSourceID="SqlDataSource1">
                            <Columns>
                                <asp:BoundField DataField="CourseId" HeaderText="課程編號" ReadOnly="True" 
                                    SortExpression="CourseId" />
                                <asp:BoundField DataField="CourseName" HeaderText="課程名稱" 
                                    SortExpression="CourseName" />
                                <asp:BoundField DataField="Year" HeaderText="開設年份" SortExpression="Year" />
                                <asp:BoundField DataField="Semester" HeaderText="學期" 
                                    SortExpression="Semester" />
                                <asp:BoundField DataField="Intro" HeaderText="介紹" SortExpression="Intro" />
                                <asp:CheckBoxField DataField="IsLimitNum" HeaderText="是否限制人數" 
                                    SortExpression="IsLimitNum" />
                                <asp:BoundField DataField="LimitNum" HeaderText="人數上限" 
                                    SortExpression="LimitNum" />
                                <asp:BoundField DataField="Point" HeaderText="學分" SortExpression="Point" />
                                <asp:BoundField DataField="Length" HeaderText="單周時數" SortExpression="Length" />
                                <asp:CommandField ButtonType="Button" ShowEditButton="True" />
                            </Columns>
                            <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
                            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
                            <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
                            <RowStyle BackColor="White" ForeColor="#330099" />
                            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
                            <SortedAscendingCellStyle BackColor="#FEFCEB" />
                            <SortedAscendingHeaderStyle BackColor="#AF0101" />
                            <SortedDescendingCellStyle BackColor="#F6F0C0" />
                            <SortedDescendingHeaderStyle BackColor="#7E0000" />
                        </asp:GridView>
                    </td>
                </tr>
            </table>
            <br />
            <br />
        <br />
        <br />
        </div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
            DeleteCommand="DELETE FROM [Course] WHERE [CourseId] = @CourseId" 
            InsertCommand="INSERT INTO [Course] ([CourseId], [CourseName], [Year], [Semester], [Intro], [IsLimitNum], [LimitNum], [Point], [Length]) VALUES (@CourseId, @CourseName, @Year, @Semester, @Intro, @IsLimitNum, @LimitNum, @Point, @Length)" 
            SelectCommand="SELECT * FROM [Course]" 
            UpdateCommand="UPDATE [Course] SET [CourseName] = @CourseName, [Year] = @Year, [Semester] = @Semester, [Intro] = @Intro, [IsLimitNum] = @IsLimitNum, [LimitNum] = @LimitNum, [Point] = @Point, [Length] = @Length WHERE [CourseId] = @CourseId">
            <DeleteParameters>
                <asp:Parameter Name="CourseId" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="CourseId" Type="Int32" />
                <asp:Parameter Name="CourseName" Type="String" />
                <asp:Parameter Name="Year" Type="String" />
                <asp:Parameter Name="Semester" Type="Int32" />
                <asp:Parameter Name="Intro" Type="String" />
                <asp:Parameter Name="IsLimitNum" Type="Boolean" />
                <asp:Parameter Name="LimitNum" Type="Int32" />
                <asp:Parameter Name="Point" Type="Int32" />
                <asp:Parameter Name="Length" Type="Int32" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="CourseName" Type="String" />
                <asp:Parameter Name="Year" Type="String" />
                <asp:Parameter Name="Semester" Type="Int32" />
                <asp:Parameter Name="Intro" Type="String" />
                <asp:Parameter Name="IsLimitNum" Type="Boolean" />
                <asp:Parameter Name="LimitNum" Type="Int32" />
                <asp:Parameter Name="Point" Type="Int32" />
                <asp:Parameter Name="Length" Type="Int32" />
                <asp:Parameter Name="CourseId" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
    
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
            SelectCommand="SELECT [Year] FROM [Course]"></asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
            DeleteCommand="DELETE FROM [Course] WHERE [CourseId] = @CourseId" 
            InsertCommand="INSERT INTO [Course] ([CourseId], [CourseName], [Year], [Semester], [Intro], [IsLimitNum], [LimitNum], [Point], [Length]) VALUES (@CourseId, @CourseName, @Year, @Semester, @Intro, @IsLimitNum, @LimitNum, @Point, @Length)" 
            SelectCommand="SELECT * FROM [Course] WHERE ([Year] = @Year)" 
            UpdateCommand="UPDATE [Course] SET [CourseName] = @CourseName, [Year] = @Year, [Semester] = @Semester, [Intro] = @Intro, [IsLimitNum] = @IsLimitNum, [LimitNum] = @LimitNum, [Point] = @Point, [Length] = @Length WHERE [CourseId] = @CourseId">
            <DeleteParameters>
                <asp:Parameter Name="CourseId" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="CourseId" Type="Int32" />
                <asp:Parameter Name="CourseName" Type="String" />
                <asp:Parameter Name="Year" Type="String" />
                <asp:Parameter Name="Semester" Type="Int32" />
                <asp:Parameter Name="Intro" Type="String" />
                <asp:Parameter Name="IsLimitNum" Type="Boolean" />
                <asp:Parameter Name="LimitNum" Type="Int32" />
                <asp:Parameter Name="Point" Type="Int32" />
                <asp:Parameter Name="Length" Type="Int32" />
            </InsertParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="Year" 
                    PropertyName="SelectedValue" Type="String" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="CourseName" Type="String" />
                <asp:Parameter Name="Year" Type="String" />
                <asp:Parameter Name="Semester" Type="Int32" />
                <asp:Parameter Name="Intro" Type="String" />
                <asp:Parameter Name="IsLimitNum" Type="Boolean" />
                <asp:Parameter Name="LimitNum" Type="Int32" />
                <asp:Parameter Name="Point" Type="Int32" />
                <asp:Parameter Name="Length" Type="Int32" />
                <asp:Parameter Name="CourseId" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>
